package com.xtkj.superclub_friendscircle.controller;

import com.xtkj.commons.JsonResult;
import com.xtkj.commons.TokenUtil;
import com.xtkj.superclub_entity.entity.friendsCircle.ShareComment;
import com.xtkj.superclub_entity.entity.friendsCircle.ShareReply;
import com.xtkj.superclub_friendscircle.service.ICommentReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 项目名称：superclub
 * 类 名 称：CommentController
 * 类 描 述：TODO
 * 创建时间：2020/1/6 11:23
 * 创 建 人：xiezhiyan
 */
@RestController
@RequestMapping("/commentreply")
@Api(value = "CommentController", tags = {"朋友圈评论回复restful api"})
public class CommentController {

    @Autowired
    private ICommentReplyService commentReplyService;



    @RequestMapping(value = "/comment", method = RequestMethod.POST)
    @ApiOperation(value ="发起评论",httpMethod = "POST",produces = "application/json")
    @ApiImplicitParams({@ApiImplicitParam(name = "shareComment",value ="评论的内容",required = true)})
    public JsonResult friendsCircleComment(HttpServletRequest request, @RequestBody ShareComment shareComment) {
        try {
            String commentUserId = TokenUtil.getUserId(request.getHeader("token"));
            shareComment.setCommentUserId(commentUserId);
            commentReplyService.friendsCircleComment(shareComment);
            return  JsonResult.success().setCode(200).setMsg("添加评论成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  JsonResult.error().setCode(500).setMsg("异常");
        }
    }

    @RequestMapping(value = "/reply", method = RequestMethod.POST)
    public  JsonResult friendsCircleReply(HttpServletRequest request,@RequestBody ShareReply shareReply){
        try {
            String replyUserId = TokenUtil.getUserId(request.getHeader("token"));
            shareReply.setReplyId(replyUserId);
            commentReplyService.friendsCircleReply(shareReply);
            return  JsonResult.success().setCode(200).setMsg("回复评论成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  JsonResult.error().setCode(500).setMsg("异常");
        }
    }

}